home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / tlog.cpp < prev    next >
C/C++ Source or Header  |  1998-01-05  |  8KB  |  331 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW IDE                       |
  4. // |  File:        TLOG.CPP                             |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     Tlog class implementation            |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. #define uses_stdarg
  16. #define uses_stdio
  17. #define uses_string
  18.  
  19. #define uses_app
  20. #define uses_desk
  21. #define uses_editor
  22. #define uses_ht
  23. #define uses_system
  24. #define uses_table
  25.  
  26. #include "PVUSES.H"
  27. #include "TERRMON.H"
  28.  
  29. #define _DECLARE_TLOG_H
  30.   #include "TLOG.H"
  31. #undef  _DECLARE_TLOG_H
  32.  
  33.  
  34. /*
  35. LOG ENTRY
  36. */
  37.   struct Tlog_entry
  38.   {
  39.     uint x;
  40.     uint y;
  41.     uint offset;
  42.     char *message;
  43.     char filename[_MAX_PATH];
  44.   };
  45.   #define TLOG_ENTRY_SIZE ( sizeof( Tlog_entry ) - _MAX_PATH )
  46.  
  47.   static void free_log_entry( void *p )
  48.   {
  49.     FREE( ( (Tlog_entry *) p)->message );
  50.   }
  51.  
  52.  
  53. /*
  54. public
  55. */
  56.   Tlog::Tlog( int _xl, int _yl ):
  57.     Thide_on_close( _xl, _yl )
  58.   {
  59.     data_size = TLOG_ENTRY_SIZE;
  60.     lb_item_killer = free_log_entry;
  61.     local_key( this, cmLOG_GOTO, kENTER );
  62.     scroll_ahead = 1;
  63.   }
  64.  
  65.   #pragma off( unreferenced )
  66.   void Tlog::editors_supervisor( char *file_name, uint where, int bytes, int lines )
  67.   {
  68.     Tlog_entry *me;
  69.     uint i;
  70.  
  71.     for( i = 0; i < vcount; i++ )
  72.     {
  73.       me = (Tlog_entry *) getptr( i );
  74.       if( ( *me->filename ) &&
  75.           ( me->offset != (uint) -1 ) &&
  76.           ( strcmp( file_name, me->filename ) == 0 ) &&
  77.           ( me->offset >= where ) )
  78.         me->offset = max( where, me->offset + bytes );
  79.     }
  80.   }
  81.   #pragma on( unreferenced )
  82.  
  83.   void Tlog::clip_copy( void )
  84.   {
  85.     Tlog_entry *me;
  86.     uint pos, i;
  87.  
  88.     clipboard->delete_select();
  89.     pos = clipboard->cur_ptr;
  90.     for( i = 0; i < vcount; i++ )
  91.     {
  92.       me = (Tlog_entry *) getptr( i );
  93.       if( !clipboard->insert_string(me->message,0) ) break;
  94.       clipboard->new_line();
  95.     }
  96.     clipboard->set_select( pos, clipboard->cur_ptr, 1 );
  97.   }
  98.  
  99.   void Tlog::logout( char *text, ... )
  100.   {
  101.     Tlog_entry me;
  102.     char buf[256];
  103.     va_list argptr;
  104.     va_start( argptr, text );
  105.     vsprintf( buf, text, argptr );
  106.     va_end( argptr );
  107.     me.x = me.y = 0;
  108.     me.offset = 0;
  109.     me.message = STRDUP( buf );
  110.     *me.filename = 0;
  111.     add( &me );
  112.     update_commands();
  113.   }
  114.  
  115.   void Tlog::load( char *filename )
  116.   {
  117.     FILE *f;
  118.     char buf[256], *s0, *s1, *s2, *s3, *p;
  119.     Tlog_entry me;
  120.  
  121.     f = fopen( filename, "rt" );
  122.     if( f == NULL ) return;
  123.     while( !feof( f ) && ( fgets( buf, 255, f ) != NULL ) )
  124.     {
  125.       if( ( p = strchr( buf, '\n' ) ) != NULL ) *p = 0;
  126.       s0 = buf;                          while( *s0 && ( *s0 == ' ' ) ) s0++;
  127.       s1 = strchr( s0, ',' ); *s1++ = 0; while( *s1 && ( *s1 == ' ' ) ) s1++;
  128.       s2 = strchr( s1, ',' ); *s2++ = 0; while( *s2 && ( *s2 == ' ' ) ) s2++;
  129.       s3 = strchr( s2, ',' ); *s3++ = 0; while( *s3 && ( *s3 == ' ' ) ) s3++;
  130.       me.x = atol( s2 ) - 1; me.y = atol( s1 ) - 1;
  131.       me.offset = (uint) -1;
  132.       me.message = STRDUP( s3 );
  133.       strcpy( me.filename, s0 );
  134.       if( *s0 ) fexpand( me.filename );
  135.       add( &me );
  136.     }
  137.     fclose( f );
  138.     Tlb_list::bottom();
  139.     owner->resize( owner->xl, owner->yl );
  140.     update_commands();
  141.   }
  142.  
  143.   void Tlog::show_first_error( void )
  144.   {
  145.     Tlog_entry *me;
  146.     uint i;
  147.  
  148.     if( !vcount ) return;
  149.     win_log();
  150.     Tlb_list::bottom();
  151.     for( i = 0; i < vcount; i++ )
  152.     {
  153.       me = (Tlog_entry *) getptr( i );
  154.       if( *me->filename != 0 )
  155.       {
  156.         Tlb_list::at( i );
  157.         break;
  158.       }
  159.     }
  160.     show_error( 1 );
  161.   }
  162.  
  163.   #pragma off( unreferenced )
  164.   void Tlog::fetch( char *buffer, uint row, uint column, uint width )
  165.   {
  166.     Tlog_entry *me = (Tlog_entry *) getptr( row );
  167.     switch( column )
  168.     {
  169.       case 0:
  170.         *buffer = 0;
  171.         if( *me->filename==0 ) return;
  172.         strcpy( buffer, me->filename );
  173.         min_path( buffer );
  174.         short_path( buffer, width );
  175.         break;
  176.       case 1:
  177.         if( row==vcurrent ) text_attr = selected_attr;
  178.         strncpy( buffer, me->message, 255 );
  179.     }
  180.   }
  181.   #pragma on( unreferenced )
  182.  
  183.   void Tlog::show_error( boolean focused )
  184.   {
  185.     Tlog_entry *me, *me1;
  186.     char *editor_name;
  187.     int i;
  188.  
  189.     set_state( isHIDDEN, 0 );
  190.     if( err_mon != NULL ) DELETE( err_mon );
  191.     err_mon = NULL;
  192.     if( vcurrent >= vcount ) return;
  193.     me = (Tlog_entry *) getptr( vcurrent );
  194.     if( *me->filename==0 )
  195.     {
  196.       focus();
  197.       return;
  198.     }
  199.     for( Tfile_editor *f=open_editors; f!=NULL; f=f->next_editor )
  200.       if( strcmp( me->filename, f->text_editor->file_name ) == 0 ) break;
  201.     if( f==NULL && focused )
  202.     {
  203.       focus();
  204.       return;
  205.     }
  206.     _help( htW_EDITOR );
  207.     edit_file( me->filename );
  208.     if( ( current_editor == NULL ) ||
  209.         ( strcmp( editor_name = ((Tfile_editor *) current_editor->editor)->text_editor->file_name,
  210.                   me->filename ) != 0 ) ) return;
  211.     for( i = 0; i < vcount; i++ )
  212.     {
  213.       me1 = (Tlog_entry *) getptr( i );
  214.       if( ( me1->offset == (uint) -1 ) && !strcmp( editor_name, me1->filename ) )
  215.       {
  216.         current_editor->set_cur_xy( me1->x, me1->y, 0 );
  217.         me1->offset = current_editor->cur_ptr;
  218.       }
  219.     }
  220.     current_editor->set_cur_ptr( me->offset, 0 );
  221.     current_editor->editor->track_cursor( 1 );
  222.     if( focused )
  223.     {
  224.       current_editor->set_select(
  225.         current_editor->line_start( current_editor->cur_ptr ),
  226.         current_editor->next_line( current_editor->cur_ptr ), 0 );
  227.       focus();
  228.     }
  229.     else
  230.       err_mon = NEW( Terror_monitor( me->message, current_editor->editor ) );
  231.   }
  232.  
  233.   void Tlog::nexterr( boolean focused )
  234.   {
  235.     if( vcurrent + 1 >= vcount ) return;
  236.     Tlb_list::down();
  237.     redraw();
  238.     show_error( focused );
  239.   }
  240.  
  241.   void Tlog::preverr( boolean focused )
  242.   {
  243.     if( vcurrent == 0 ) return;
  244.     Tlb_list::up();
  245.     redraw();
  246.     show_error( focused );
  247.   }
  248.  
  249.  
  250. /*
  251. protected
  252. */
  253.   void Tlog::event_handler( Tevent &ev )
  254.   {
  255.     uint v;
  256.  
  257.     v = vcurrent;
  258.     Thide_on_close::event_handler( ev );
  259.     if( v != vcurrent ) show_error( state( isFOCUSED ) );
  260.     if( ev.code==evCOMMAND )
  261.     {
  262.       switch( ev.CMD_CODE )
  263.       {
  264.         case cmLOG_CLEAR:
  265.           clear();
  266.           break;
  267.         case cmLOG_CLIP_COPY:
  268.           clip_copy();
  269.           break;
  270.         case cmLOG_GOTO:
  271.           if( state(isFOCUSED) )
  272.           {
  273.             show_error( 0 );
  274.             break;
  275.           }
  276.         default:
  277.           return;
  278.       }
  279.       redraw();
  280.       handled( ev );
  281.     }
  282.   }
  283.  
  284.   void Tlog::update_commands( void )
  285.   {
  286.     cstate( cmLOG_GOTO, vcount );
  287.     cstate( cmLOG_CLEAR, vcount );
  288.     cstate( cmLOG_CLIP_COPY, vcount );
  289.   }
  290.  
  291.  
  292. /*
  293. INTERFACE
  294. */
  295.   void construct_log( void )
  296.   {
  297.     Ttable *tbl;
  298.  
  299.     if( log != NULL ) DELETE( log->owner->owner );
  300.     _help( htW_LOGOUT );
  301.     construct_table( "Log", log = NEW( Tlog( desktop_xl, desktop_yl / 3 ) ) );
  302.       tdata( "Destination", 12, 12 );
  303.       tdata( "Message", 255, 255 );
  304.     _context( cxLOG );
  305.     tbl = endt();
  306.     tbl->set_title_vtab( -1 );
  307.     ( (Twindow *) tbl->owner )->palette = wpTOOL;
  308.     local_key( tbl->owner, cmOK, kENTER );
  309.     tbl->owner->set_flags( ifTILEABLE, 0 );
  310.     insert_window( tbl->owner, 0, desktop_yl - tbl->owner->yl );
  311.   }
  312.  
  313.   void win_log( void )
  314.   {
  315.     log->set_state( isHIDDEN, 0 );
  316.     log->owner->owner->set_state( isICONIZED, 0 );
  317.     log->focus();
  318.   }
  319.  
  320.   void log_nexterr( void )
  321.   //show next compiler's error
  322.   {
  323.     log->nexterr( 0 );
  324.   }
  325.  
  326.   void log_preverr( void )
  327.   //show previous com